package top.maof.book.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.vdurmont.emoji.EmojiParser;

import java.io.IOException;

/**
 * jackson序列化器
 * 将emojiStr解码成emojiUnicode
 * :blush: --> 😊
 */
public class EmojiSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String emojiStr, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String emojiUnicode = EmojiParser.parseToUnicode(emojiStr);
        jsonGenerator.writeString(emojiUnicode);
    }
}
